<div class="layui-fluid layui-anim febs-anim" id="febs-dictDetail" lay-title="活动数据字典明细">
    <div class="layui-row febs-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body febs-table-full">
                    <form class="layui-form layui-table-form" lay-filter="dict-table-form">
                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">字典明细名称</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="name" autocomplete="off" class="layui-input">
                                            <p id="dictIdVal" style="display: none;" th:text="${dictId}"></p>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action" id="queryDetail">
                                    <i class="layui-icon">&#xe848;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action" id="resetDetail">
                                    <i class="layui-icon">&#xe79b;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action action-more"
                                     shiro:hasAnyPermissions="shellActivityDetailDic:add,shellActivityDetailDic:update,shellActivityDetailDic:delete">
                                    <i class="layui-icon">&#xe875;</i>
                                </div>
                            </div>
                        </div>
                    </form>
                    <div>
                        <p style="font-weight:bold"  th:text="${activityDic.name}"></p>
                    </div>
                    <table lay-filter="dictDetailTable" lay-data="{id: 'dictDetailTable'}"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="dictDetatl-option">
    <span shiro:lacksPermission="shellActivityDetailDic:add,shellActivityDetailDic:update,shellActivityDetailDic:delete">
        <span class="layui-badge-dot febs-bg-orange"></span> 无权限
    </span>
    <span shiro:hasPermission="shellActivityDetailDic:update"><button lay-event="update" type="button" class="layui-btn layui-btn-xs">修改</button></span>
    <span shiro:hasPermission="shellActivityDetailDic:delete"><button lay-event="delete" type="button" class="layui-btn layui-btn-xs">删除</button></span>
</script>
<script data-th-inline="none" type="text/javascript">
    layui.use(['dropdown', 'jquery', 'laydate', 'form', 'table', 'febs'], function () {
        var $ = layui.jquery,
            laydate = layui.laydate,
            febs = layui.febs,
            form = layui.form,
            table = layui.table,
            dropdown = layui.dropdown,
            $view = $('#febs-dictDetail'),
            dictId = $('#dictIdVal').text(),
            $queryDetail = $view.find('#queryDetail'),
            $resetDetail = $view.find('#resetDetail'),
            $searchForm = $view.find('form'),
            sortObject = {field: 'fromDate', type: null},
            tableIns;

        form.render();
        initTable();

        laydate.render({
            elem: '#fromDate',
            range: true,
            trigger: 'click'
        });
        dropdown.render({
            elem: $view.find('.action-more'),
            click: function (name, elem, event) {
                var checkStatus = table.checkStatus('dictDetailTable');
                if (name === 'add') {
                    localStorage.setItem('dictDetailVal', '');
                    febs.modal.open('新增活动字典明细', '/activity/shellActivityDetailDic/add/' + dictId, {
                        area: $(window).width() <= 750 ? '90%' : '50%'
                    });
                }
                if (name === 'delete') {
                    if (!checkStatus.data.length) {
                        febs.alert.warn('请选择需要删除的活动数据字典');
                    } else {
                        febs.modal.confirm('删除活动数据字典', '确定删除活动数据字典？', function () {
                            var Ids = [];
                            layui.each(checkStatus.data, function (key, item) {
                                Ids.push(item.id)
                            });
                            deleteOilPrice(Ids.join(','));
                        });
                    }
                }
            },
            options: [{
                name: 'add',
                title: '新增字典明细',
                perms: 'shellActivityDetailDic:add'
            }, {
                name: 'delete',
                title: '删除字典明细',
                perms: 'shellActivityDetailDic:delete'
            }]
        });

        table.on('tool(dictDetailTable)', function (obj) {
            var data = obj.data,
                layEvent = obj.event;
            var dataString = JSON.stringify(data);
            if (layEvent === 'update') {
                localStorage.setItem('dictDetailVal', dataString);
                febs.modal.open('修改活动字典明细', 'activity/shellActivityDetailDic/add/' + dictId, {
                    area: $(window).width() <= 750 ? '90%' : '50%'
                });
            }
            if (layEvent === 'delete') {
                febs.modal.confirm('删除活动数据字典', '确定删除该活动数据字典？', function () {
                    deleteOilPrice(data.id);
                });
            }
            if (layEvent === 'info') {
                febs.modal.open('活动字典明细',{
                    content: '',
                    btn: ['确定'],
                    area: $(window).width() <= 750 ? '90%' : '50%',
                    yes: function (index, layero) {

                    }
                })
            }
        });

        $queryDetail.on('click', function () {
            var params = $.extend(getQueryParams(), {});
            tableIns.reload({where: params, page: {curr: 1}});
        });

        $resetDetail.on('click', function () {
            $searchForm[0].reset();
            tableIns.reload({where: getQueryParams(), page: {curr: 1}});
        });
        //列表数据-请求
        function initTable() {
            tableIns = febs.table.init({
                elem: $view.find('table'),
                id: 'dictDetailTable',
                url: ctx + 'shellActivity/dictDetailList?parentId=' + dictId,
                cols: [[
                    {type: 'checkbox'},
                    {field: 'name', title: '字典明细名称', minWidth: 100},
                    {field: 'code', title: '字典明细编码', minWidth: 100},
                    {field: 'dicValue', title: '默认值', minWidth: 100},
                    {field: 'remark', title: '备注', minWidth: 100},
                    {title: '操作', toolbar: '#dictDetatl-option', minWidth: 100}
                ]]
            });
        }

        function getQueryParams() {
            return {
                name: $searchForm.find('input[name="name"]').val()
            };
        }

        function deleteOilPrice(Ids) {
            console.log(Ids);
            febs.get(ctx + 'shellActivity/dicDetailDelete/' + Ids , null, function () {
                febs.alert.success('删除活动数据字典成功');
                $queryDetail.click();
            });
        }

    })
</script>